﻿using LD.Common;
using LD.Host;
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using YTE.Control;

namespace LD
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool Running = false;
            System.Threading.Mutex mutex = new System.Threading.Mutex(true, "LD", out Running);

            if (!Running)
            {
                MessageBox.Show("程序已经启动");
                return;
            }
            Log4.Init();
            Init();
            Language.Init();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            Application.Run(new MyContext());
            mutex.ReleaseMutex();
        }
        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Log4.Error(e.Exception);
            FormSysMessage.ShowException(new CustomException(e.Exception.Message, ExceptionType.Error)); // 调用FormSysMessage窗体，显示异常信息。
        }
        private static void Init()
        {
            string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config");
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
        }
    }
}
